package com.atguigu.r2dbc.controller;

import com.atguigu.r2dbc.entity.StudentDO;
import org.springframework.web.bind.annotation.*;

import reactor.core.publisher.Flux;

import com.atguigu.r2dbc.service.StudentService;
import reactor.core.publisher.Mono;

@RestController
@RequestMapping("/student")
public class StudentController {
    private final StudentService service;

    public StudentController(StudentService service) {
        this.service = service;
    }

    @GetMapping("/findAll")
    public Flux<StudentDO> findAll() {
        return service.findAll();
    }

    @GetMapping("/find/{id}")
    public Mono<StudentDO> findById(@PathVariable Long id) {
        return service.findById(id);
    }

    @PostMapping("/save")
    public Mono<StudentDO> save(StudentDO student) {
        return service.save(student);
    }

    @PutMapping("/update")
    public Mono<StudentDO> update(StudentDO studennt) {
        return service.update(studennt);
    }

    @DeleteMapping("/delete/{id}")
    public Mono<Void> delete(@PathVariable Long id) {
        return service.deleteById(id);
    }
}
